package com.jm.product.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.google.common.collect.Lists;
/**
 * 产品管理Entity
 * @author sunshine
 * @version 2017-07-04
 */
@Entity
@Table(name = "es_product")
@Cache(region = "com.jm.cache", usage = CacheConcurrencyStrategy.READ_WRITE)
public class Product extends IdEntity<Integer> implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
    @Column(name="name")
	private String name;//name
    @Column(name="sn")
	private String sn;//sn
    @Column(name="store")
	private Integer store;//store
    @Column(name="price")
	private Double price;//price
    @Column(name="specs")
	private String specs;//specs
    @Column(name="cost")
	private Double cost;//cost
    @Column(name="weight")
	private Double weight;//weight

    @ManyToOne
    @JoinColumn(name="goods_id")
    private Goods goods ;
    
    @OneToMany(mappedBy="product")
    private List<GoodsSpec> goodsSpecMap = Lists.newArrayList() ;
    
    @Transient
    private List<SpecValues> specList;

	public Product() {
		super();
	}
	
	/**
	*
	* get name
	*
	* return name
	*/
	public String getName() {
		return this.name;
	}
	
	/**
	 * 
	 * set name
	 * 
	 * @param name
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	*
	* get sn
	*
	* return sn
	*/
	public String getSn() {
		return this.sn;
	}
	
	/**
	 * 
	 * set sn
	 * 
	 * @param sn
	 */
	public void setSn(String sn) {
		this.sn = sn;
	}
	/**
	*
	* get store
	*
	* return store
	*/
	public Integer getStore() {
		return this.store;
	}
	
	/**
	 * 
	 * set store
	 * 
	 * @param store
	 */
	public void setStore(Integer store) {
		this.store = store;
	}
	/**
	*
	* get price
	*
	* return price
	*/
	public Double getPrice() {
		return this.price;
	}
	
	/**
	 * 
	 * set price
	 * 
	 * @param price
	 */
	public void setPrice(Double price) {
		this.price = price;
	}
	/**
	*
	* get specs
	*
	* return specs
	*/
	public String getSpecs() {
		return this.specs;
	}
	
	/**
	 * 
	 * set specs
	 * 
	 * @param specs
	 */
	public void setSpecs(String specs) {
		this.specs = specs;
	}
	/**
	*
	* get cost
	*
	* return cost
	*/
	public Double getCost() {
		return this.cost;
	}
	
	/**
	 * 
	 * set cost
	 * 
	 * @param cost
	 */
	public void setCost(Double cost) {
		this.cost = cost;
	}
	/**
	*
	* get weight
	*
	* return weight
	*/
	public Double getWeight() {
		return this.weight;
	}
	
	/**
	 * 
	 * set weight
	 * 
	 * @param weight
	 */
	public void setWeight(Double weight) {
		this.weight = weight;
	}

	public Goods getGoods() {
		return goods;
	}

	public void setGoods(Goods goods) {
		this.goods = goods;
	}

	public List<GoodsSpec> getGoodsSpecMap() {
		return goodsSpecMap;
	}

	public void setGoodsSpecMap(List<GoodsSpec> goodsSpecMap) {
		this.goodsSpecMap = goodsSpecMap;
	}

	public List<SpecValues> getSpecList() {
		return specList;
	}

	public void setSpecList(List<SpecValues> specList) {
		this.specList = specList;
	}

	@Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        result = prime * result + ((sn == null) ? 0 : sn.hashCode());
        result = prime * result + ((store == null) ? 0 : store.hashCode());
        result = prime * result + ((price == null) ? 0 : price.hashCode());
        result = prime * result + ((specs == null) ? 0 : specs.hashCode());
        result = prime * result + ((cost == null) ? 0 : cost.hashCode());
        result = prime * result + ((weight == null) ? 0 : weight.hashCode());
        return result;
    }
	
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Product other = (Product) obj;
        if (id == null) {
            if (other.id != null)
                return false;
        } else if (!id.equals(other.id))
            return false;
        if (name == null) {
            if (other.name != null)
                return false;
        } else if (!name.equals(other.name))
            return false;
        if (sn == null) {
            if (other.sn != null)
                return false;
        } else if (!sn.equals(other.sn))
            return false;
        if (store == null) {
            if (other.store != null)
                return false;
        } else if (!store.equals(other.store))
            return false;
        if (price == null) {
            if (other.price != null)
                return false;
        } else if (!price.equals(other.price))
            return false;
        if (specs == null) {
            if (other.specs != null)
                return false;
        } else if (!specs.equals(other.specs))
            return false;
        if (cost == null) {
            if (other.cost != null)
                return false;
        } else if (!cost.equals(other.cost))
            return false;
        if (weight == null) {
            if (other.weight != null)
                return false;
        } else if (!weight.equals(other.weight))
            return false;
        return true;
    }
	
 	@Override
    public String toString() {
        return "Product [id=" + id + ",name=" + name + ",sn=" + sn + ",store=" + store + ",price=" + price + ",specs=" + specs + ",cost=" + cost + ",weight=" + weight + "]";
    }
}


